// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init({
  env: cloud.DYNAMIC_CURRENT_ENV
})

const db = cloud.database()
const _ = db.command

/**
 * 保存请求或线索
 */
exports.main = async (event, context) => {
  const { OPENID } = cloud.getWXContext()
  return await db.collection('request')
    .add({
      data: {
        _openid: OPENID,
        type: event.type,
        notice_id: event.notice_id,
        receiver_id: event.receiver_id,
        requester: event.requester,
        phone: event.phone,
        region: event.region,
        description: event.description,
        images: event.images,
        status: 0,
        tosee: 0,
        create: Date.now()
      }
    })
}